/*!  \file  ThreadPool.h
 *	  \brief  
 * 
 *   \details   details
 *   \author    Yordan Madzhunkov German Research School for Simulation Sciences GmbH
 *   \version   1.0
 *   \date      07/13/2013 07:18:42 PM
 *   \copyright GNU Public License.
 */
#pragma once
class TaskManager;
typedef void* (*ThreadFunction)(void*);

struct WorkerInfo {
	TaskManager * manager;
	int tID;
};

class ThreadPool {
public:
	ThreadPool(const int MaxNumThreads = 16); 
	virtual ~ThreadPool();
	void execute(const ThreadFunction func,  const int nThreads_ = -1,
		 WorkerInfo * args = NULL, void ** retVals = NULL);
	static int getOnlineCores();
private:
	DISALLOW_COPY_AND_ASSIGN(ThreadPool);
	void joinAll(void ** retVals); // all threads are joined. Only the master threads will continue

	pthread_t   *   threadIDs; // array with posix thread IDs
	TaskManager * taskManager; // class that will manage tasks

	int nThreads; // number of currently creaded threads
	int maxThreads; // number of maximum threads
};
